#include<stdio.h>
#include<SDL/SDL.h>
#include<stdlib.h>
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "fonction.h"



/*void deplacernum(SDL_Surface *num,SDL_Surface *screen,SDL_Surface *image,SDL_Rect number)
{
    int done=1,i=0;
    int but=1;
    int d=1;
    SDL_Surface *select=NULL;
    SDL_Rect PosSelect;
    SDL_Event event;
    SDL_SetColorKey( num, SDL_SRCCOLORKEY, SDL_MapRGB(num->format, 255, 255, 255) );
    select=SDL_LoadBMP("select.bmp");
    while (done)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
        case SDL_QUIT:
            done= 0;
            break;

        case (SDL_MOUSEBUTTONDOWN):


            if (((event.button.x)>150)&&(event.button.x<189)&&((event.button.y)>92)&&(((event.button.y)<145)))
            {

                SDL_EnableKeyRepeat(100, 100);
                number.x=169;
                number.y=118;
                PosSelect.x=150;
                PosSelect.y=92;
                SDL_BlitSurface(select,NULL,image,&PosSelect);

            }
            else if (((event.button.x)>271)&&(event.button.x<312)&&((event.button.y)>92)&&(((event.button.y)<145)))
            {
                 SDL_EnableKeyRepeat(100, 100);
                number.x=169;
                number.y=118;
                PosSelect.x=271;
                PosSelect.y=92;
                SDL_BlitSurface(select,NULL,image,&PosSelect);

            }
            else if (((event.button.x)>150)&&(event.button.x<312)&&((event.button.y)>247)&&(((event.button.y)<301)))
            {
                SDL_EnableKeyRepeat(100, 100);
                number.x=169;
                number.y=118;
                PosSelect.x=150;
                PosSelect.y=248;
                SDL_BlitSurface(select,NULL,image,&PosSelect);
            }

            break;
        case SDL_KEYDOWN:
            switch (event.key.keysym.sym)
            {
            case SDLK_KP1:
                i=1;
            break;
            case SDLK_KP2:
                i=2;
            break;
            case SDLK_KP3:
                i=3;
            break;
            case SDLK_KP4:
                i=4;
            break;
            case SDLK_KP5:
                i=5;
            break;
            case SDLK_KP6:
                i=6;
            break;
            case SDLK_KP7:
                i=7;
            break;
            case SDLK_KP8:
                i=8;
            break;
            case SDLK_KP9:
                i=9;
            break;

            }

        }
        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255,255));
        SDL_BlitSurface(image, NULL, screen,NULL);
  switch(i)
 {
 case 1:
    SDL_BlitSurface(num, NULL, screen, &number);
break;



 }






        /*SDL_BlitSurface(num, NULL, screen, &number);
        SDL_Flip(screen);
    }

    SDL_Quit();
}
*/





void jouer(SDL_Surface *screen)

{

    SDL_Surface *image;
    SDL_Surface *num1,*num2,*num3,*num4,*num5,*num6,*num7,*num8,*num9,*num0;
    SDL_Surface *num11,*num22,*num33,*num44,*num55,*num66,*num77,*num88,*num99,*num00;
    SDL_Surface *num111,*num222,*num333,*num444,*num555,*num666,*num777,*num888,*num999,*num000;
    SDL_Rect number;
    screen = SDL_SetVideoMode(500, 500, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
    image = SDL_LoadBMP("img/fond_jeu.bmp");
    num1= SDL_LoadBMP("img/T/1.bmp");
    num2=SDL_LoadBMP("img/T/2.bmp");
    num3= SDL_LoadBMP("img/T/3.bmp");
    num4= SDL_LoadBMP("img/T/4.bmp");
    num5= SDL_LoadBMP("img/T/5.bmp");
    num6= SDL_LoadBMP("img/T/6.bmp");
    num7= SDL_LoadBMP("img/T/7.bmp");
    num8= SDL_LoadBMP("img/T/8.bmp");
    num9= SDL_LoadBMP("img/T/9.bmp");
    num0= SDL_LoadBMP("img/T/0.bmp");
    num11= SDL_LoadBMP("img/V/11.bmp");
    num22=SDL_LoadBMP("img/V/22.bmp");
    num33= SDL_LoadBMP("img/V/33.bmp");
    num44= SDL_LoadBMP("img/V/44.bmp");
    num55= SDL_LoadBMP("img/V/55.bmp");
    num66= SDL_LoadBMP("img/V/66.bmp");
    num77= SDL_LoadBMP("img/V/77.bmp");
    num88= SDL_LoadBMP("img/V/88.bmp");
    num99= SDL_LoadBMP("img/V/99.bmp");
    num00= SDL_LoadBMP("img/V/00.bmp");
    num111= SDL_LoadBMP("img/N/111.bmp");
    num222=SDL_LoadBMP("img/N/222.bmp");
    num333= SDL_LoadBMP("img/N/333.bmp");
    num444= SDL_LoadBMP("img/N/444.bmp");
    num555= SDL_LoadBMP("img/N/555.bmp");
    num666= SDL_LoadBMP("img/N/666.bmp");
    num777= SDL_LoadBMP("img/N/777.bmp");
    num888= SDL_LoadBMP("img/N/888.bmp");
    num999= SDL_LoadBMP("img/N/999.bmp");
    num000= SDL_LoadBMP("img/N/000.bmp");
    SDL_SetColorKey( num1, SDL_SRCCOLORKEY, SDL_MapRGB(num->format, 255, 255, 255) );
int done=1,i=0;
    int but=1;
    int d=1;
    SDL_Surface *select=NULL;
    SDL_Rect PosSelect;
    SDL_Event event;
    SDL_SetColorKey( num, SDL_SRCCOLORKEY, SDL_MapRGB(num->format, 255, 255, 255) );
    select=SDL_LoadBMP("select.bmp");
    while (done)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
        case SDL_QUIT:
            done= 0;
            break;

        case (SDL_MOUSEBUTTONDOWN):


            if (((event.button.x)>150)&&(event.button.x<189)&&((event.button.y)>92)&&(((event.button.y)<145)))
            {

                SDL_EnableKeyRepeat(100, 100);
                number.x=169;
                number.y=118;
                PosSelect.x=150;
                PosSelect.y=92;
                SDL_BlitSurface(select,NULL,image,&PosSelect);

            }
            else if (((event.button.x)>271)&&(event.button.x<312)&&((event.button.y)>92)&&(((event.button.y)<145)))
            {
                 SDL_EnableKeyRepeat(100, 100);
                number.x=169;
                number.y=118;
                PosSelect.x=271;
                PosSelect.y=92;
                SDL_BlitSurface(select,NULL,image,&PosSelect);

            }
            else if (((event.button.x)>150)&&(event.button.x<312)&&((event.button.y)>247)&&(((event.button.y)<301)))
            {
                SDL_EnableKeyRepeat(100, 100);
                number.x=169;
                number.y=118;
                PosSelect.x=150;
                PosSelect.y=248;
                SDL_BlitSurface(select,NULL,image,&PosSelect);
            }

            break;
        case SDL_KEYDOWN:
            {SDL_EnableKeyRepeat(100, 100);
            switch (event.key.keysym.sym)
            {
            case SDLK_KP0:
                i=0;
            case SDLK_KP1:
                i=1;
            break;
            case SDLK_KP2:
                i=2;
            break;
            case SDLK_KP3:
                i=3;
            break;
            case SDLK_KP4:
                i=4;
            break;
            case SDLK_KP5:
                i=5;
            break;
            case SDLK_KP6:
                i=6;
            break;
            case SDLK_KP7:
                i=7;
            break;
            case SDLK_KP8:
                i=8;
            break;
            case SDLK_KP9:
                i=9;
            break;

            }
            }

        }
        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255,255));
        SDL_BlitSurface(image, NULL, screen,NULL);
  switch(i)
 {
 case 1:
    SDL_BlitSurface(num1, NULL, screen, &PosSelect);
break;
 case 2:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 3:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 4:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 5:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 6:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 7:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 8:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 9:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;
case 0:

    SDL_BlitSurface(num2, NULL, screen, &PosSelect);
break;

 }






        /*SDL_BlitSurface(num, NULL, screen, &number);*/
        SDL_Flip(screen);
    }
    SDL_Quit();



    SDL_FreeSurface(image);

}




